Skip to content

Conversation

@trmartin4
Copy link
Member

@trmartin4 trmartin4 commented Oct 29, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-27593

📔 Objective

We would like to document that the HandlebarsMailService has been deprecated in favor of the Mailer, and also add documentation in code about the support guarantees of our disk overrides of mail templates, so that there is no confusion in the future about this feature and its expectations.

Creating a "home" for the documentation that made sense required moving the mail-related services out of the shared Services folder and into their own "feature" folder. This is our current best practice and allows contextual, close-to-code READMEs for developer and AI usage.

With this change:

  1. All mail-related services live in the Mail folder.
  2. All mail-related services are in the Platform.Mail namespace, with the exception of the deprecated IMailService and HandlebarsMailService. These were not moved from Services because it would introduce more than 100 files to the PR.
  3. All mail-related services are documented together in one README at the Mail folder level.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@trmartin4 trmartin4 changed the title Added docs for legacy mail service. Add docs for legacy mail service Oct 29, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 29, 2025

Logo
Checkmarx One – Scan Summary & Details662dabe8-9798-4d4a-af3f-c3d5ea68d539

Fixed Issues (1)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/Billing/Controllers/VNext/AccountBillingVNextController.cs: 72

@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.27%. Comparing base (b4d6f3c) to head (6ca20ac).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6513   +/-   ##
=======================================
  Coverage   52.27%   52.27%           
=======================================
  Files        1909     1909           
  Lines       84598    84598           
  Branches     7558     7558           
=======================================
  Hits        44223    44223           
  Misses      38659    38659           
  Partials     1716     1716           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trmartin4 trmartin4 changed the title Add docs for legacy mail service [PM-27593] Add docs for legacy mail service Oct 29, 2025
@trmartin4 trmartin4 marked this pull request as ready for review October 29, 2025 13:52
@trmartin4 trmartin4 requested a review from a team as a code owner October 29, 2025 13:52
@trmartin4 trmartin4 requested review from coroiu and kspearrin October 29, 2025 13:52
coroiu
coroiu previously approved these changes Oct 29, 2025
@claude
Copy link

claude bot commented Oct 29, 2025

Claude finished @trmartin4's task —— View job


Code Review Complete

I've completed a comprehensive review of this PR. The changes look solid overall - this is a well-executed refactoring that improves code organization and adds important documentation. Below are my findings:


Summary of Changes

This PR reorganizes mail-related services into a dedicated Platform/Mail folder structure and adds comprehensive documentation about the deprecated HandlebarsMailService and the modern Mailer approach. Key changes:

  1. File moves: Mail services moved from Services to Platform/Mail with subfolder organization (Delivery, Enqueuing, Mailer)
  2. Namespace changes: New namespace Bit.Core.Platform.Mail.* (except deprecated services kept in Bit.Core.Services namespace to avoid 100+ file changes)
  3. Documentation: Enhanced README with deprecation notices and disk override support guarantees
  4. Formatting: Applied dotnet format to align with PR [PM-24192] Move account recovery logic to command #6184 changes

Critical Issues Found

None identified.


Suggested Improvements

1. README Documentation - Minor Clarity Issues

Location: src/Core/Platform/Mail/README.md:78

Issue: Character encoding issue in the text template example

{{ CurrentYear }} Bitwarden Inc.

Suggestion: Replace with the proper copyright symbol © or spell out "(c)"


2. Deprecation Attributes - Consider Adding More Context

Locations:

  • src/Core/Platform/Mail/HandlebarsMailService.cs:35
  • src/Core/Platform/Mail/IMailService.cs:15

Current:

[Obsolete("The IMailService has been deprecated in favor of the IMailer. All new emails should be sent with an IMailer implementation.")]

Suggestion: Consider adding a URL parameter to direct developers to migration docs:

[Obsolete("The IMailService has been deprecated in favor of the IMailer. All new emails should be sent with an IMailer implementation.", DiagnosticId = "BW0001", UrlFormat = "https://contributing.bitwarden.com/architecture/server/mail")]

This provides IDE integration and easier access to migration guidance.


3. README - Disk Override Documentation Could Be More Prominent

Location: src/Core/Platform/Mail/README.md:209

Current: The critical warning about backward compatibility for disk overrides is at the bottom of a long README.

Suggestion: Consider adding a warning callout at the top of the README or in a separate DISK_OVERRIDES.md file since this is important for self-hosted customers. The current placement may be missed by developers making breaking changes.


4. Namespace Consistency - Minor Inconsistency

Observation: The PR description mentions keeping IMailService and HandlebarsMailService in the old namespace to avoid 100+ file changes. This is pragmatic, but creates a slight inconsistency where:

  • File location: src/Core/Platform/Mail/HandlebarsMailService.cs
  • Namespace: Bit.Core.Services.Mail

Suggestion: This is acceptable given the deprecated status, but consider adding a TODO comment in the deprecated classes:

// TODO: When removing this deprecated service, also clean up the namespace inconsistency
// This service lives in Platform/Mail but uses the Services namespace to avoid breaking 100+ files

5. Service Registration - Good Practice Observed

Location: src/SharedWeb/Utilities/ServiceCollectionExtensions.cs:249-253

Observation: Excellent separation of concerns with clear comments:

// Legacy mailer service
services.AddSingleton<IMailService, HandlebarsMailService>();
// Modern mailers
services.AddMailer();

This makes the migration path very clear. Well done! 👍


Good Practices Observed

  • ✅ Proper use of [Obsolete] attributes on deprecated services
  • ✅ Comprehensive README with clear examples and architecture documentation
  • ✅ Consistent file organization following feature folder pattern
  • ✅ All test files updated with correct namespace imports
  • ✅ Clear separation between legacy and modern mail services in DI registration
  • ✅ No breaking changes to existing APIs (backward compatible)
  • ✅ Proper documentation of support guarantees for self-hosted disk overrides

Security & Performance Considerations

Security: No security concerns identified. The changes are purely organizational with no modifications to mail content handling or sensitive data processing.

Performance: No performance impact. This is a refactoring with no changes to execution logic.

Zero-knowledge compliance: No impact on vault data or encryption. Mail services handle only metadata and notifications.


Action Items for Author

  1. Required: Fix the character encoding issue in README.md line 78 (replace with © or "(c)")

  2. Recommended: Consider adding diagnostic ID and URL to [Obsolete] attributes for better developer experience

  3. Optional: Consider making disk override documentation more prominent (separate file or warning callout at top of README)

  4. Optional: Add TODO comments about namespace inconsistency in deprecated files for future cleanup


Verdict

This is a well-executed refactoring that significantly improves code organization and documentation. The approach of moving files while maintaining backward compatibility is pragmatic and minimizes risk. The only required change is the minor README encoding fix.

Recommendation: ✅ Approve after addressing the character encoding issue


kspearrin
kspearrin previously approved these changes Oct 29, 2025
@@ -1,5 +1,5 @@
using Bit.Core.Models.Mail;
using Bit.Core.Services;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does mailer go to it's own namespace and not just in ..Services.Mail, for example?

@trmartin4 trmartin4 dismissed stale reviews from kspearrin and coroiu via e78c7f4 November 2, 2025 01:13
@trmartin4 trmartin4 requested a review from coroiu November 3, 2025 21:37
@trmartin4 trmartin4 requested a review from a team as a code owner November 3, 2025 21:40
@trmartin4 trmartin4 requested a review from BTreston November 3, 2025 21:40
@trmartin4
Copy link
Member Author

@BTreston it looks like when I run dotnet format it adjusts the formatting of the changes in #6184, and linting fails otherwise in CI. Let me know if you'd prefer this in a separate PR.

Copy link
Contributor

@BTreston BTreston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the dotnet format changes 👍

@trmartin4 trmartin4 merged commit 3668a44 into main Nov 4, 2025
45 checks passed
@trmartin4 trmartin4 deleted the platform/add-handlbars-mail-service-docs branch November 4, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants